/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package databasehandling;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import model.Event;
import model.EventType;

/**
 *
 * @author Malene
 */
public class EventHandler {

    /**
     * Opretter en liste med alle bestilte events
     *
     * @return ArrayList med de events der blev fundet i databasen
     * @throws SQLException
     * @throws ParseException
     */
    public ArrayList<Event> hentAlleEvents() throws SQLException, ParseException {

        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
        ArrayList<Event> eventlist = new ArrayList<>();
        ResultSet rs = DatabaseHandler.getInstance().select("CALL `HentAlleEvents`()");
        while (rs.next()) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(sdf.parse(rs.getString("DatoTid")));
            eventlist.add(new Event(rs.getInt("ID"), cal, rs.getInt("AntalBestilte"), rs.getInt("AntalFremmødte"), rs.getString("Sted"), rs.getString("KundeTlf"),
                    new EventType(rs.getInt("EventTypeID"), rs.getString("Navn"), rs.getInt("prisDKK"), rs.getInt("prisEURO"))));
        }
        return eventlist;
    }

}
